<script>
export default {
  name: 'cart component',
  data() {
    return {
        cart: []
    }
  },
  created() {
    // 尝试从 sessionStorage 中获取购物车
    let cart = sessionStorage.getItem( 'shoppingCart' );
    this.cart = cart ? JSON.parse(cart) : this.cart;
    console.log( this.cart );
  }
}
</script>

<template>
  <div class="cart">
    <el-row v-for="(item,index) in cart" :key="item.id" class="item" align="middle">
        <el-col :span="4">{{index+1}}</el-col>
        <el-col :span="10">{{item.name}}</el-col>
        <el-col :span="4">{{item.price}}</el-col>
        <el-col :span="3">{{item.amount}}</el-col>
        <el-col :span="3">{{item.price * item.amount}}</el-col>
    </el-row>
  </div>
</template>